1244C - The Football Season - CodeForces Solution


brute force math number theory *2000

Please click on ads to support us..

Python Code:

import sys, os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

n, p, w, d = map(int, input().split())
ans = [-1]
l = pow(10, 6) + 5
for y in range(min(n, l) + 1):
    u = p - y * d
    if u < 0:
        break
    if u % w:
        continue
    x = u // w
    z = n - x - y
    if z >= 0:
        ans = [x, y, z]
        break
sys.stdout.write(" ".join(map(str, ans)))

C++ Code:

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e6+10;
const int mod=1e9+7;
/*int exgcd(int a,int b,int &x,int &y){
	if(b==0){
		x=0,y=1;
		return a;
	}
	int d=exgcd(b,a%b,y,x);
	y-=x*a/b;
	return d;
}*/
signed main(){
	ios::sync_with_stdio(false);cin.tie(0);
	int n,p,w,d;
	cin>>n>>p>>w>>d;
	for(int i=0;i<w;i++){
		if((p-i*d)%w==0&&i+(p-i*d)/w<=n&&p>=i*d){
			int x=(p-i*d)/w,y=i,z=n-x-y;
			cout<<x<<' '<<y<<' '<<z<<'\n';
			return 0;
		}
	}
	cout<<"-1\n";
}


Comments

Submit
0 Comments
More Questions

1512D - Corrupted Array
667B - Coat of Anticubism
284B - Cows and Poker Game
1666D - Deletive Editing
1433D - Districts Connection
2B - The least round way
1324A - Yet Another Tetris Problem
246B - Increase and Decrease
22E - Scheme
1566A - Median Maximization
1278A - Shuffle Hashing
1666F - Fancy Stack
1354A - Alarm Clock
1543B - Customising the Track
1337A - Ichihime and Triangle
1366A - Shovels and Swords
919A - Supermarket
630C - Lucky Numbers
1208B - Uniqueness
1384A - Common Prefixes
371A - K-Periodic Array
1542A - Odd Set
1567B - MEXor Mixup
669A - Little Artem and Presents
691B - s-palindrome
851A - Arpa and a research in Mexican wave
811A - Vladik and Courtesy
1006B - Polycarp's Practice
1422A - Fence
21D - Traveling Graph